package com.bnlr.lrparking.util;

import android.text.TextUtils;
import com.google.gson.Gson;
import com.bnlr.lrparking.app.Application;
import com.bnlr.lrparking.model.User;


/**
 * Created by MeiNiu-Scholar on 2016/12/7 0007.
 */
public class UserModel {
    public static void save(User user) {
        String s = new Gson().toJson(user);
        Application.mPreferenceHelper.getSpWriter().putString("user", s).commit();
        Application.mUser = user;
    }
    public static User read() {
        String driver =  Application.mPreferenceHelper.getSpReader().getString("user", null);
        if (TextUtils.isEmpty(driver)) {
            return null;
        }
        return new Gson().fromJson(driver, User.class);
    }
    public static void clear() {
        Application.mPreferenceHelper.getSpWriter().putString("user", "").commit();
        Application.mUser = null;
    }
}
